﻿using System;
using GC_FFW.Common.Abstractions.Interfaces.Helpers;
using GC_FFW.SoccerfameParser.Abstractions.Interfaces.Factories;
using GC_FFW.SoccerfameParser.Abstractions.Interfaces.Services;
using GC_FFW.SoccerfameParser.Services;

namespace GC_FFW.SoccerfameParser.Factories
{
	public class SoccerfameDataHelperFactory : ISoccerfameDataHelperFactory
	{
		#region Variables

		private readonly INamesService _teamNamesService;
		private readonly INamesService _playerNamesService;

		private readonly IRepositoryFactory _repositoryFactory;

		#endregion

		#region Properties

		public INamesService TeamNamesService
		{
			get { return _teamNamesService; }
		}
		public INamesService PlayerNamesService
		{
			get { return _playerNamesService; }
		}

		#endregion

		#region Constructors

		public SoccerfameDataHelperFactory(IApplicationConfiguration applicationConfiguration, IRepositoryFactory repositoryFactory)
		{
			if (applicationConfiguration == null)
				throw new ArgumentNullException(string.Format("applicationConfiguration"));

			if (repositoryFactory == null)
				throw new ArgumentNullException(string.Format("repositoryFactory"));
			_repositoryFactory = repositoryFactory;

			_teamNamesService = CreateNamesService(applicationConfiguration.TeamNamesDataFilePath);
			_playerNamesService = CreateNamesService(applicationConfiguration.PlayerNamesDataFilePath);
		}

		#endregion

		#region ISoccerfameDataHelperFactory Members

		public INamesService CreateNamesService(string filePath)
		{
			return new NamesService(_repositoryFactory.Create(filePath));
		}

		#endregion
	}
}
